function loadPage(pagina,sezione,param,metod,callback,showWait,isXMLserverReq)
{			
	if(showWait == null )
		$('#'+sezione).html('<div><div class="attendere"></div></div>');
	
	var type= "html";	
	
	if(isXMLserverReq  != undefined && isXMLserverReq != null && isXMLserverReq != "undefined")
		type = "xml";
	
	$.ajax({type: metod,
			url: ''+pagina+'.php?'+''+param,				
			dataType: type,	
			cache:false,		
			
			success: function(html)
			{						
				if(isXMLserverReq  == undefined || isXMLserverReq == null || isXMLserverReq == "undefined")
					$('#'+sezione).html(html).show();				
				
				if(callback != undefined && callback != null && callback != "undefined")
				{				
					if(isXMLserverReq  != undefined && isXMLserverReq != null && isXMLserverReq != "undefined")
					{				
						callback.call(callback,html);
					}
					else
					{
						callback.call();	
					}
				}
			}
	});
}			

function onServerRequest(formId,callback)
{		
	$pageTocall = $('#'+formId).attr('action');
	$method = $('#'+formId).attr('method');
	var values = {};
		$.each($('#'+formId).serializeArray(), function(i, field) {
			values[field.name] = field.value;
		});

	
	if($method == 'post')
	{
		$.post($pageTocall,values,
		   function(xml)
		   {				
				if(callback != undefined && callback != null && callback != "undefined")				
						callback.call(callback,xml);
		   });	
	}	
}

function trackEventAnalytics(category,action,opt_label,opt_value,opt_noninteraction)
{
	//category, action, opt_label, opt_value, opt_noninteraction
	/*
	String   category The general event category (e.g. "Videos"). 

	String   action The action for the event (e.g. "Play"). 
	
	String   opt_label An optional descriptor for the event.
	
	Int      opt_value An optional value associated with the event. You can see your event values in the Overview, Categories, and Actions reports, where they are listed by event or aggregated across events, depending upon your report view.
	
	Boolean  opt_noninteraction Default value is false. By default, the event hit sent by _trackEvent() will impact a visitor's bounce rate. By setting this parameter to true, this event hit will not be used in bounce rate calculations.
	*/
	//_gaq.push(['_trackEvent', 'Videos', 'Stop', 'Gone With the Wind']);
	
	if(opt_noninteraction == undefined)
		opt_noninteraction = false;
		
	if(opt_label == undefined)	
		opt_label = '';
		
	if(opt_value == undefined)	
		_gaq.push(['_trackEvent', category, action, opt_label]);	
	else
		_gaq.push(['_trackEvent', category, action, opt_label, opt_value, false]);	
}


function checkCookie(cookie)
{
	var c = getCookie("panerai_catalogo");
	if (c != null)
	{
	  //apro il form subscibe
	  //window.location.href=linkCatalogoFlipping;
	  if(navigator.platform.indexOf("iPad") != -1 || navigator.platform.indexOf("iPhone") != -1)
	  window.location.href=linkCatalogoFlipping;
	  else
	  window.open(linkCatalogoFlipping);
	  
	  //return;
	  
	}
}

function getCookie(name)
{
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) 
  {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function setCookie(name, value, days)
{
  if (days) 
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = '; expires='+date.toGMTString();
  }
  else var expires = '';
  document.cookie = name+'='+value+expires+'; path=/';
}

function addEventSocialGTM(socialPlatform,socialAction)
{
	dataLayer.push({"socialPlatform":socialPlatform,"socialAction": socialAction,"event": "clickSocialButton"});
}

function addEventGTM(eventType)
{
	dataLayer.push({"event":eventType});
}

function trackEventTabWatch(tab)
{
	dataLayer.push({"navTabName": tab,"event": "clicNavTab"});
}

var timeOutOverSocial = "";
$(document).ready(function(){
	
	$('.ico-social-group').mouseover(function(){
		
		if(timeOutOverSocial != "")
		{
			return;
			//clearTimeout(timeOutOverSocial);
			//timeOutOverSocial = "";
		}
		
		var nSocial = $(this).parent('.wrap_social_over_product').find('.item_social').length;
		var hSocialItem = parseInt($(this).parent('.wrap_social_over_product').find('.item_social').height(),10);
		var marginSocialItem = parseInt($(this).parent('.wrap_social_over_product').find('.item_social').css('margin-top'),10);		
		var newHeigh = (hSocialItem*nSocial + marginSocialItem*nSocial) + marginSocialItem;
		
		$('.sub_wrap_social_hover').animate({
		height: newHeigh+"px",
		top: "-"+(newHeigh+5)+"px"
		},500);
		
	});
	
	$('.ico-social-group').mouseout(function(){
		timeOutOverSocial = setTimeout("hideSocialOverProduct()",500);
	});
	
	$('.sub_wrap_social_hover').mouseover(function(){
		clearTimeout(timeOutOverSocial);
		timeOutOverSocial = "";
	});
	
	$('.sub_wrap_social_hover').mouseout(function(){
		timeOutOverSocial = setTimeout("hideSocialOverProduct()",500);
	});
	
	$('#footer .bt_minimize_footer_home, #footer .f_action, #footer .parent > .separator').click(function() {
	    if($("#footer").css('bottom') == "-100px") {
	        $( "#footer" ).animate(
	                {bottom:"0px"}, 
	                500,
	                function() {$('#footer .bt_minimize_footer_home').css('background-position','top left')}
	        );
	    } else {
	        $( "#footer" ).animate(
	                {bottom:"-100px"}, 
	                500,
                    function() {$('#footer .bt_minimize_footer_home').css('background-position','bottom left')}
	        );
	    }
	});
	
	$('#footer a.fb').click(function(event) {
	    addEventSocialGTM('facebook','official page')
	});    
    $('#footer a.tw').click(function(event) {
        addEventSocialGTM('twitter','official page')
    });    
    $('#footer a.you').click(function(event) {
        addEventSocialGTM('youtube','official page')
    });    
    $('#footer a.go').click(function(event) {
        addEventSocialGTM('google','official page')
    });    
    $('#footer a.linked').click(function(event) {
        addEventSocialGTM('linkedin','official page')
    });    
    $('#footer a.pn').click(function(event) {
        addEventSocialGTM('pinterest','official page')
    });
    $('#footer a.as').click(function(event) {
        addEventGTM('appstore')
    });
	
})

function hideSocialOverProduct()
{		
	$('.sub_wrap_social_hover').animate({
	height: "0px",
	top: "0px",
	bottom: "45px"
	},500);
	
	timeOutOverSocial = "";
}
